<template>
       <div class="department-wrap">
          <el-dialog 
          title="部门授权"
           :visible.sync="DepartmentDialogVisible"
           @open='sendAjax'
           @close = 'handleClose'
           top='3vh'
            >
    

            <section class="selected-down" @click='selectFlag = true'>
              <el-select v-model="defaultValue"  @change='handleSelect' placeholder="请选择">
                <el-option
                  v-for="(k,i) in res.secondDept"
                  :label="k.descrshort"
                  :value="k.setid"
                  :key='i'
                 >
                </el-option>
              </el-select>
            </section>


            <section class="tree" ref='departmentTree'>
               <div class='dialog-body'>
                 <!-- <el-tree
                 class='nolazy'
                  v-if='!isLazy'
                  :data="res.deptTree && res.deptTree[0]"
                  :props="defaultProps"
                  :render-content="renderContent"
                  :default-checked-keys	='res.CheckDeptId'
                  node-key='deptid'
                  ref='departmentElTree'
                  :key='new Date().getTime()'
                  :default-expanded-keys	='defaultExpand'
                  accordion
                  >
                </el-tree> -->

                <halo-tree  ref="deptTreeAuto" :treeDataLevelSave.sync='treeDataLevelSave' :levelNum.sync="levelNum" :isLazy.sync="isLazy" type="Group" class="lt widthTree" :treeData.sync="datasTree" :treeDataSave="treeDataSave"></halo-tree>

                
              </div> 


            </section>

             <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="save">保 存</el-button>
                <el-button @click="changeVisible">取 消</el-button>
             </span>
    
        </el-dialog>
       </div>
</template>

<script>
import Vue from 'vue';
import {
  Checkbox,
  CheckboxGroup,
  Button,
  Dialog,
  Tree,
  Select,
  Option,
  MessageBox,
  Message
} from 'element-ui';

Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Button);
Vue.use(Dialog);
Vue.use(Select);
Vue.use(Option);
Vue.use(Tree);
import URL from '@/common/js/adminUrl';
import haloTree from '@/components/userManager/dialog/treeDeptN'
export default {
  created() {
    Bus.$on(
      '部门授权',
      data => (this.DepartmentDialogVisible = data.department)
    );
    Bus.$on('identify', data => (this.identify = data));
    Bus.$on('setid', data => (this.setid = data));
  },
  data() {
    return {
      DepartmentDialogVisible: false,
      identify: '',
      res: '',
      defaultValue: '',
      defaultChecked: '',
      defaultProps: {
        children: 'treeList',
        label: 'descr',
        isLeaf: 'whe_sub'
      },
      selectFlag: false,
      selected: 'label sele',
      noselected: 'label',
      deptid: {
        all: [],
        flag: null
      },
      levelNum:2,
      isLazy: false,
      defaultExpand: [],
      setid: '',
      isPersonnelClick: false,
      isPayClick: false,
      arr: {
        pay: [],
        personnel: []
      },
      datasTree:[],

      treeData:[],
      treeDataSave:[],
      treeDataLevelSave:[],

      lastCheckedArr:[],

      isFirstTime:true,
    };
  },

  components:{
      haloTree,
  },

  computed: {
    treeLength() {
      return this.res.deptTree.length;
    }
  },

  methods: {
    handleClose() {
      this.isPayClick = false;
      this.isPersonnelClick = false;
      this.isLazy = false;
    },
    intersect() {
            var result = new Array();
            var obj = {};
            for (var i = 0; i < arguments.length; i++) {
                if (!arguments[i] || !arguments[i].length) {
                    return [];
                }
                for (var j = 0; j < arguments[i].length; j++) {

                    var str = arguments[i][j];

                    if (!obj[str]) {
                        obj[str] = 1;
                    }
                    else {
                        obj[str]++;
                        if (obj[str] == arguments.length)
                        {
                            result.push(str);
                        }
                    }
                }
            }
            return result;
    },
    minus (arrOne,arr) {
            if (!arr || !arr.length) {
                return arrOne;
            }
            var result = new Array();
            var obj = {};
            for (var i = 0; i < arr.length; i++) {
                obj[arr[i]] = 1;
            }
            for (var j = 0; j < arrOne.length; j++) {
                if (!obj[arrOne[j]])
                {
                    obj[arrOne[j]] = 1;
                    result.push(arrOne[j]);
                }
            }
            return result;
    },
    loadNode(node, resolve) {
      const level = node.level;

      if (level === this.treeLength || !this.res.deptTree[level].length) {
        return resolve([]);
      }

      setTimeout(() => {
        let data = [];

        let isPayAll = 0,
          isPersonnelAll = 0;
        if (document.querySelector(`#b${node.data.level_num}`)) {
          isPayAll = document
            .querySelector(`#b${node.data.level_num}`)
            .className.includes('sele');
        }

        if (document.querySelector(`#a${node.data.level_num}`)) {
          isPersonnelAll = document
            .querySelector(`#a${node.data.level_num}`)
            .className.includes('sele');
        }

        this.res.deptTree[level].forEach((ele, i, arr) => {
          if (ele.level_num.indexOf(node.data.level_num) >= 0) {
            data.push({
              treeList: ele.treeList,
              descr: ele.descr,
              deptid: ele.deptid,
              level: ele.level,
              level_num: ele.level_num,
              setid: ele.setid,
              whe_sub: ele.whe_sub,
              // personnel: this.isPersonnelClick?personnelSelect:ele.personnel,
              // pay: this.isPayClick?paySelect:ele.pay
              personnel: (() => {
                if (isPersonnelAll) {
                  return 1;
                } else if (this.isPersonnelAll) {
                  return isPersonnelAll - 0;
                } else {
                  return ele.personnel;
                }
              })(),
              pay: (() => {
                if (isPayAll) {
                  return 1;
                } else if (this.isPayClick) {
                  return isPayAll - 0;
                } else {
                  return ele.pay;
                }
              })()
            });
          }
        });

        resolve(data);
      }, 0);
    },

    stopPropagation(e) {
      if (e && e.stopPropagation) {
        e.stopPropagation();
      } else {
        window.event.cancelBubble = true;
      }
    },

    // level_num: "002001", deptid: "1000000", personnel: 1, pay: 1
    // 获取所有点击的节点 和该节点的 level层级 


    setStatusArr({ level, level_num , type }) {
      const arrStore = type == 'a' ? this.arr.personnel : this.arr.pay;


      // let minLen = 100,
      //   minLenTargt = null;

      // arrStore.length > 1 && arrStore.forEach((ele, index, arr) => {
      //     if (ele.length < minLen) {
      //       minLen = ele.length;
      //       minLenTargt = ele;
      //     }
      //   });

      // if (minLenTargt) {
      //   console.log(minLenTargt, 'minLenTargt');
      //   arrStore.forEach((ele, i, arr) => {
      //     if (ele.startsWith(minLenTargt) && ele !== minLenTargt) {
      //       console.log(ele, 'ele');
      //       console.log(minLenTargt, 'minLenTargt');
      //       arr.splice(i, 1);
      //     }
      //   });
      // }

      // console.log(arrStore, 'arrStore');
    },

    handlePersonnel(node, data, e) {
      if (e && e.stopPropagation) {
        e.stopPropagation();
      } else {
        window.event.cancelBubble = true;
      }

      this.isPersonnelClick = true;

      const ref = this.$refs.departmentTree;
      const strStart = data.level_num;
      const target = ref.querySelector(`#a${strStart}`);
      const targetStatus = target.className == this.selected ? true : false;
      const domList = ref.querySelectorAll('label');
      let father = node.parent && node.parent.data.level_num;

      for (let i = 0; i < domList.length; i++) {
        if (domList[i].id.startsWith(`a${strStart}`)) {
          if (targetStatus) {
            domList[i].className = this.noselected;
          } else {
            domList[i].className = this.selected;
          }
        }
      }


      this.handleIsAll({
        status: targetStatus,
        level_num: strStart,
        father,
        type: 'a',
        level: data.level
      });
    },

    handleIsAll({ status, type, level_num, level, father = null } = {}) {
      this.setStatusArr({ target: level, type });

      if (!father) {
        return;
      }

      const ref = this.$refs.departmentTree;
      let fatherNode = ref.querySelector(`#${type}${father}`);
      const target = ref.querySelector(`#${type}${level_num}`);
      const allDom = ref.querySelectorAll('.label');
      let brotherNode = [];
      for (let i = 0; i < allDom.length; i++) {
        if (
          allDom[i].id.startsWith(`${type}${father}`) &&
          allDom[i].id !== `${type}${father}`
        ) {
          brotherNode.push(allDom[i]);
        }
      }

      if (!status) {
        // 判断其他兄弟节点是否选中,如果是 父节点选中
        let brotherAllSelect = true;
        for (let i = 0; i < brotherNode.length; i++) {
          if (brotherNode[i].className !== this.selected) {
            brotherAllSelect = false;
          }
        }

        if (brotherAllSelect) {
          fatherNode.className = this.selected;
        }
      } else {
        // 父节点取消选中
        fatherNode.className = this.noselected;
      }
    },
    handlePay(node, data, e) {
      if (e && e.stopPropagation) {
        e.stopPropagation();
      } else {
        window.event.cancelBubble = true;
      }

      this.isPayClick = true;

      const ref = this.$refs.departmentTree;
      const strStart = data.level_num;
      const target = ref.querySelector(`#b${strStart}`);
      const targetStatus = target.className == this.selected ? true : false;
      const domList = ref.querySelectorAll('label');
      let father = node.parent && node.parent.data.level_num;

      for (let i = 0; i < domList.length; i++) {
        if (domList[i].id.startsWith(`b${strStart}`)) {
          if (targetStatus) {
            domList[i].className = this.noselected;
          } else {
            domList[i].className = this.selected;
          }
        }
      }
      this.handleIsAll({
        status: targetStatus,
        level_num: strStart,
        father,
        type: 'b',
        level: data.level
      });
    },

    renderContent(h, { node, data, store }) {
      return (
        <span style="overflow:hidden; font-size: 14px; padding-right: 8px;">
          <span>
            <span>{node.label}</span>
          </span>
          <span
            style="float:right;margin-right:15px"
            on-click={$event => this.stopPropagation($event)}
          >
            <label
              class={data.personnel ? this.selected : this.noselected}
              style="margin-right:16px"
              id={'a' + data.level_num}
              data-id={'a' + data.deptid}
              on-click={$event => this.handlePersonnel(node, data, $event)}
            />
            <i class="name-type1">人事</i>
            <label
              class={data.pay ? this.selected : this.noselected}
              style="margin-right:6px"
              data-id={'b' + data.deptid}
              id={'b' + data.level_num}
              on-click={$event => this.handlePay(node, data, $event)}
            />
            <i class="name-type2">薪酬</i>
          </span>
        </span>
      );
    },
    handleSelect(val) {
      if (this.isFirstTime) {
          return;
      }

      this.isPayClick = false;
      this.isPersonnelClick = false;



      let params = {
        identify: this.identify,
        setId: val,
        roleSetid: this.setid
      };

      this.Axios.Post(this.URL.querydeptAuth.url, params).then(res => {
        const datas = res.data.datas;

        this.res = datas;

        this.lastCheckedArr = datas.CheckDept;
        this.treeDataLevelSave = this.iterateArray(this.lastCheckedArr);
        console.log(this.treeDataLevelSave,'this.treeDataLevelSave');

        this.datasTree = datas.deptTree;

        var rootTreeNode = []
        for (var n = 0; n<=this.datasTree.length-1; n++) {
            console.log(this.datasTree[n].length,n);
            rootTreeNode = rootTreeNode.concat(this.datasTree[n])
        }
        console.log(rootTreeNode.length,'TotalNode');

        var totalResultStr = []
        rootTreeNode.forEach((val)=>{
            totalResultStr.push(val.level_num);
        })
        console.log(rootTreeNode.length,'TotalNode');


        // this.handleDefaultExpand(datas);

        if (val === 'CM016' || val === 'CM002' || val === 'CM900') {
            this.isLazy = true;
        } else {
            this.isLazy = false;
        }  

        this.treeDataSave = JSON.parse(JSON.stringify(this.datasTree));

        

       

        // this.$refs.departmentElTree.setCheckedKeys(this.res.CheckDeptId);
      });
    },

    handleDefaultExpand(datas) {
      this.defaultExpand = [];

      if (datas.deptTree && datas.deptTree[0]) {
        for (let q = 0; q < datas.deptTree[0].length; q++) {
          this.defaultExpand.push(datas.deptTree[0][q].deptid);
        }
      }
    },

    handleTreeData(data, start, end = 0) {
      //先找到列表运算末级与末级的上一级
      //将末级push到上一级
      //依次运算整合到第一级数据  从而完成树状结构
      const len = data.deptTree.length;

      if (!start) {
        start = len - 1;
      }

      for (let index = start; index > end; index--) {
        data.deptTree[index - 1].forEach(x => {
          data.deptTree[index].forEach(k => {
            if (k.level_num.indexOf(x.level_num) >= 0) {
              if (!x.treeList) {
                x.treeList = [];
              }

              // data.CheckDept.forEach(ele => {
              //   if (k.deptid == ele.department_id) {
              //     k.personnel = ele.personnel;
              //     k.pay = ele.pay;
              //   }
              // });

              x.treeList.push(k);
            }
          });
        });
      }
    },

    sendAjax() {
      this.Axios.Post(
        this.URL.deptAuth.url +
          '?identify=' +
          this.identify +
          '&roleSetid=' +
          this.setid
      ).then(res => {
        this.res = res.data.datas;

        const datas = res.data.datas;

        this.datasTree = datas.deptTree



        this.lastCheckedArr = datas.CheckDept;

        this.treeDataLevelSave = this.iterateArray(this.lastCheckedArr);

        if (this.setid === 'CM016' || this.setid === 'CM002' || this.setid === 'CM900') {
            this.isLazy = true;
        } else {
            this.isLazy = false;
        }        

        this.defaultChecked = datas.CheckDept
        this.handleDefaultExpand(datas);

        // 根据节后台返回的setId 决定下拉菜单的默认值
        this.res.secondDept.forEach((ele, i) => {
          if (this.res.secondDept[i].setid == this.res.setId) {
            this.defaultValue = this.res.secondDept[i].setid;
          }
        }, this);
        Vue.nextTick(()=>{
            this.isFirstTime = false;
        })
        
        this.treeDataSave = JSON.parse(JSON.stringify(this.datasTree));
        // this.handleTreeData(datas);
      });
    },

    iterateArray(lastCheckedArr){
        var lastLevelArr = [];
        for (var i=0,len = lastCheckedArr.length;i<len;i++) {
            var level = lastCheckedArr[i].level-1;

            if (!lastLevelArr[level]) {
                lastLevelArr[level] = [];
                lastLevelArr[level].push(lastCheckedArr[i]);
            } else {
                lastLevelArr[level].push(lastCheckedArr[i]);
            }
            
        }
        return lastLevelArr;
    },

    iterateStrArray(lastCheckedArr){
        var lastLevelArr = [];
        for (var i=0,len = lastCheckedArr.length;i<len;i++) {
            var level = (lastCheckedArr[i].length - 6) / 3;

            if (!lastLevelArr[level]) {
                lastLevelArr[level] = [];
                lastLevelArr[level].push(lastCheckedArr[i]);
            } else {
                lastLevelArr[level].push(lastCheckedArr[i]);
            }
            
        }
        return lastLevelArr;
    },

    getTailNode:function(addLevelArr){
        var result = JSON.parse(JSON.stringify(addLevelArr));

        for (var k = addLevelArr.length-1;k>=0;k--) {
            if (k-1<0) {
                break;
            }
            if (!addLevelArr[k-1] || !addLevelArr[k] || !addLevelArr[k].length) {
                continue;
            }
            for (var z=0; z < addLevelArr[k].length;z++) {
                for (let y=0; y < addLevelArr[k-1].length;y++) {
                    if (addLevelArr[k][z].indexOf(addLevelArr[k-1][y]) >= 0) {
                        
                        // if (!minusArr[k-1]) {
                        //     minusArr[k-1] = []
                        // }
                        // minusArr[k-1].push(addLevelArr[k-1][y]);
            
                        result[k-1].splice(y,1);
                        // y--;
                    }


                }

            }   
            
            // if (minusArr[k-1] && minusArr[k-1].length) {
            //     for (let y=0; y < minusArr[k-1].length;y++) {
            //         if (addLevelArr[k][z].indexOf(minusArr[k-1][y]) >= 0) {
            //             addLevelArr[k-1].splice(y,1);
            //             y--;
            //         }
            //     }
            // }
        }
        return result;
    },


    getResultObjArr(){
        var getSelectedNodes = this.$refs.deptTreeAuto.$refs.tree.getSelectedNodes();
        console.log(getSelectedNodes,'getSelectedNodes');
        var result = [];
        getSelectedNodes.forEach((val,index)=>{
            if (!val.type) {
                result.push(val)
            } 
        })


        console.log(result,'result');
        console.log(this.lastCheckedArr,'this.lastCheckedArr');

        var lastLevelArr = this.iterateArray(this.lastCheckedArr);
        var resultLevelArr = this.iterateArray(result);


        
        var resultStrArr = [];

        var objPropertyResult = {};

        var lastCheckedStrArr = [];

        console.log(this.levelNum,'this.levelNum');

        for (var j=0; j<this.levelNum; j++) {
            if (j <= 1) {
                if (lastLevelArr[j]) {
                    lastLevelArr[j].forEach(val =>{
                        lastCheckedStrArr.push(val.level_num)
                    })
                }
            }
            if (resultLevelArr[j]) {
                resultLevelArr[j].forEach((val)=>{
                    resultStrArr.push(val.level_num)
                    if (j>1) {
                        objPropertyResult[val.level_num.slice(0,-3)] = 1
                    }
                })
            }

        }

        console.log(objPropertyResult,'objPropertyResult');


        //从上次选中的数组中 获取与本次选中对应的尾部节点 3级以后得子节点
        var laterThreeCheckedNodeStr = [];
        Object.keys(objPropertyResult).forEach(key=>{
            var level = (key.length - 6) / 3 + 1;
            console.log(level,'laterlevel');
            for (let i=level; i>=2; i--) {
                if (lastLevelArr[level] && lastLevelArr[level].length) {
                    for (let q=0; q<lastLevelArr[level].length; q++) {
                        if (lastLevelArr[level][q].level_num.indexOf(key)>-1) {
                            laterThreeCheckedNodeStr.push(lastLevelArr[level][q].level_num);
                        }
                    }
                }

            }
        })

        
        if (this.levelNum > 2) {
            lastCheckedStrArr = lastCheckedStrArr.concat(laterThreeCheckedNodeStr)
        }

        
        // if (lastLevelArr[j]) {
        //     lastLevelArr[j].forEach(val =>{
        //         lastCheckedStrArr.push(val.level_num)
        //     })
        // }


        var intersectArr = this.intersect(resultStrArr,lastCheckedStrArr);
  
        var minusStrArr= this.minus(lastCheckedStrArr,intersectArr);

        var addStrArr = this.minus(resultStrArr,intersectArr);


        var addLevelArr = this.iterateStrArray(addStrArr);

        
        //筛选出树节点最尾部的节点
        // for (var k = addLevelArr.length-1;k>=0;k--) {
        //     if (k-1<0) {
        //         break;
        //     }
        //     if (!addLevelArr[k-1] || !addLevelArr[k] || !addLevelArr[k].length) {
        //         continue;
        //     }
        //     for (var z=0; z < addLevelArr[k].length;z++) {
        //         for (var y=0; y < addLevelArr[k-1].length;y++) {
        //             if (addLevelArr[k][z].indexOf(addLevelArr[k-1][y]) >= 0) {
        //                 addLevelArr[k-1].splice(y,1);
        //                 y--;
        //             }
        //         }
        //     }   
        // }

        addLevelArr = this.getTailNode(addLevelArr);

        console.log(addLevelArr,'addLevelArr');
        // var addLevelObjArr = [];
        // for (let r=0;r<intersectLevelArrStr.length;r++) {
        //     for (let u=0;u<result.length;u++) {
        //         if (result[u].level_num == intersectLevelArrStr[r]) {
        //             addLevelObjArr.push(result[u]);
        //         }

        //     }
        // }

        var addLevelObjArr = JSON.parse(JSON.stringify(addLevelArr));
        for (let n = 0; n<=addLevelArr.length-1; n++) {
            if (!addLevelArr[n] || !addLevelArr[n].length) {
                continue
            } else {
                for (let r=0;r<addLevelArr[n].length;r++) {
                    for(let u=0;u<result.length;u++){
                        if (result[u].level_num == addLevelArr[n][r]) {
                            addLevelObjArr[n].splice(r,1,result[u]);
                        }                        
                    }
                }
            }

        }
        addLevelArr = addLevelObjArr;
        console.log(addLevelArr,'addLevelObjArr');

      
        //把选中根节点的 递归遍历出未加载的子节点
        var subCheckedNodeArr = [];
        for (let g = 0, len = addLevelArr.length; g< len; g++) {
            
            if (!addLevelArr[g] || !addLevelArr[g].length) {
                continue
            } else {
                for (let r=0;r<addLevelArr[g].length;r++) {
                  
                    for (let o=g,len=this.treeDataSave.length;o<len-1;o++) {

                        for (let k=0;k<this.treeDataSave[o+1].length;k++) {
                            
                            if (this.treeDataSave[o+1][k].level_num.indexOf(addLevelArr[g][r].level_num) >= 0) {
                                this.treeDataSave[o+1][k].personnel = addLevelArr[g][r].personnel;
                                this.treeDataSave[o+1][k].pay = addLevelArr[g][r].pay;
                                subCheckedNodeArr.push(this.treeDataSave[o+1][k])
                            } 
                        }
                    }
                }     
            }
        }

        console.log(subCheckedNodeArr,'subCheckedNodeArr');



        // for (let d=0; d<intersectLevelArr.length; d++) {
        //     for (let s=0;s<this.lastCheckedArr.length;s++) {
        //         if (this.lastCheckedArr[s].level_num.indexOf(minusStrArr[d]) > -1) {
        //             minusArr.push(this.lastCheckedArr[s])
        //             this.lastCheckedArr.splice(s,1);
        //             s--;
        //         }
        //     }
        // } 



        //将从上一次选中 移除掉勾选掉得节点以及其子节点
        console.log(minusStrArr,'minusStrArr');
        var minusArr = []
        for (let d=0; d<minusStrArr.length; d++) {
            for (let s=0;s<this.lastCheckedArr.length;s++) {
                if (this.lastCheckedArr[s].level_num.indexOf(minusStrArr[d]) > -1) {
                    minusArr.push(this.lastCheckedArr[s])
                    this.lastCheckedArr.splice(s,1);
                    s--;
                }
            }
        }  
    

        //将最新勾选中得节点 移到上一次选中得集合里 
        var intersectArrAdd = []
        for (let d=0; d<intersectArr.length; d++) {
            for (let s=0;s<this.lastCheckedArr.length;s++) {
                if (this.lastCheckedArr[s].level_num === intersectArr[d]) {
                    intersectArrAdd.push(this.lastCheckedArr[s])
                    this.lastCheckedArr.splice(s,1);
                    s--;
                }
            }
        }  


        //将选中的节点，push到 上一次选中的节点中
        // for (let y=0; y<addStrArr.length; y++) {
        //     for (let b=0;b<result.length;b++) {
        //         if (addStrArr[y] === result[b].level_num) {
        //             this.lastCheckedArr.push(result[b])
        //         }
        //     }
        // }

        //筛选出上次和本次交集集合中的尾部节点
        var intersectLevelArr = this.iterateStrArray(intersectArr);
        console.log(intersectLevelArr,'intersectLevelArr');
        intersectLevelArr = this.getTailNode(intersectLevelArr);

        
        var intersectLevelArrStr = [];
        for (let u=0;u<intersectLevelArr.length;u++) {
            intersectLevelArrStr = intersectLevelArrStr.concat(intersectLevelArr[u] || [])
        }
        console.log(intersectLevelArrStr,'intersectLevelArrStr');

        var intersectLevelObjArr = [];
        for (let r=0;r<intersectLevelArrStr.length;r++) {
            for (let u=0;u<result.length;u++) {
                if (result[u].level_num == intersectLevelArrStr[r]) {
                    intersectLevelObjArr.push(result[u]);
                }

            }
        }
        console.log(intersectLevelObjArr,'intersectLevelObjArr');

        //更新尾部节点 后的未加载出的人事和薪酬的数据
        for (let g=0; g<intersectLevelObjArr.length; g++) {
            for (let n=0;n<this.lastCheckedArr.length;n++) {
                if (this.lastCheckedArr[n].level_num.indexOf(intersectLevelObjArr[g].level_num) > -1) {
              
                    this.lastCheckedArr[n].personnel = intersectLevelObjArr[g].personnel ;
                    this.lastCheckedArr[n].pay = intersectLevelObjArr[g].pay ;
                    // console.log(this.lastCheckedArr[n],'this.lastCheckedArr[n]');
                }
            }
        }  


        var totalResult = this.lastCheckedArr.concat(subCheckedNodeArr);
        
        totalResult = totalResult.concat(result);

        return totalResult;

    },

    save() {

      MessageBox.confirm('确定保存?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      })
      .then(() => {

          let params = {
              identify: this.identify,
              setId: this.defaultValue,
              userDepts: this.getResultObjArr(),
              roleSetid: this.setid
          };
          console.log(params.userDepts,'params.userDepts');
          // return;
          this.Axios.Post(this.URL.saveDeptAuth.url, params).then(res => {
              if (res.data.status == 1) {
                  Message({
                    type: 'success',
                    message: '保存成功'
                  });
              }
              this.changeVisible();
          });

            
      })
      .catch(() => {});
    },
    changeVisible() {
      this.DepartmentDialogVisible = false;
    }
  }
};
</script>

<style lang='less'>
.department-wrap {
  .dialog-body {
    height: 380px;
    overflow: auto;
    .el-tree {
      border: 0;
    }
    .name-type1,
    .name-type2 {
      font-style: normal;
      position: relative;
      top: 0;
    }

    .name-type1 {
      left: -9px;
    }
    .name-type2 {
      left: 2px;
    }
  }

  .checkbox-group {
    padding: 40px 0 0 40px;
  }
  .checkbox-group div {
    margin-bottom: 10px;
  }
  .selected-down {
    margin-bottom: 12px;
  }

  .label {
    display: inline-block;
    position: relative;
    top: 4px;
    border: 1px solid #bfcbd9;
    border-radius: 4px;
    box-sizing: border-box;
    width: 18px;
    height: 18px;
    background-color: #fff;
    z-index: 1;
    cursor: pointer;
    transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
      background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
  }

  .sele {
    background-color: #20a0ff;
    border-color: #0190fe;
  }

  .sele::after {
    content: '\2714';
    color: #fff;
    position: absolute;
    left: 3px;
    top: -10px;
  }
}
</style>
